package com.nondo.dean.platform.controller.wap.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.nondo.dean.platform.domain.Slide;
import com.nondo.dean.platform.model.result.SlideResult;
import com.nondo.dean.platform.service.SlideService;

@Controller("apiWapSlide")
@RequestMapping("/wap/app/slide")
public class SlideController {
    
    @Value("${baseUrl}")
    private String baseUrl;
    
    @Autowired
    SlideService slideService;
    
    /**
     * 查看幻灯片详情
     * @param request
     * @param response
     * @param id
     * @return
     */
    @RequestMapping("/info")
    public ModelAndView goSlideDetail(HttpServletRequest request, HttpServletResponse response, Integer id) {
        ModelAndView mv = new ModelAndView("wap/app/slide/info");
        
        SlideResult slideResult = new SlideResult();
        if (id != null) {
            Slide slideDb = slideService.selectSlide(id);
            slideResult = slideService.getSlideDetail(slideDb);
            if (slideDb.getType() == 1 && StringUtils.isNotEmpty(slideDb.getValue())) {
                if (!slideDb.getValue().contains("http")) {
                    mv = new ModelAndView(slideDb.getValue());
                }
            }
        }
        mv.addObject("baseUrl", baseUrl);
        mv.addObject("slideResult", slideResult);
        return mv;
    }
    
}
